/*
 * $HEADER:$
 */
package com.ctvit.framework.dao.ibatis;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class BaseDao extends SqlMapClientDaoSupport {
	public static final String FRAMEWORK_DAO_NAMESPACE = "framework.base";

	protected Log log = LogFactory.getLog(getClass());

	/**
	 * 根据域对象返回默认的处理域对象的sqlmap命名空间。命名空间的规则以“域对象中包含的子系统编码.域对象类名”
	 * 
	 * @param clazz
	 *            域对象类
	 * @return
	 */
	protected String getDaoNameSpace(Class clazz) {
		String[] parts = StringUtils.split(clazz.getName(), ".");
		String namespace = parts[3];
		namespace += "." + parts[parts.length - 1].toLowerCase();
		return namespace;
	}

	protected String getIdName(Class clazz) {
		String clazzName = StringUtils.substringAfterLast(clazz.getName(), ".");
		return clazzName + "Id";
	}

	public Long nextId() {
		return (Long) getSqlMapClientTemplate().queryForObject(
				FRAMEWORK_DAO_NAMESPACE + ".nextId");
	}
}
